<?php

/**
 * px_payment actions.
 *
 * @package    tmdb
 * @subpackage px_payment
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class px_paymentActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->payment_list = Doctrine::getTable('Payment')
      ->createQuery('a')
     	->where('a.person_id = ?', $request->getParameter('px_id'))
      ->execute();
		$this->px_id = $request->getParameter('px_id');
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->payment = Doctrine::getTable('Payment')->find(array($request->getParameter('id')));
		$this->px_id = $this->payment->getperson_id();
    $this->forward404Unless($this->payment);
  }

  public function executeNew(sfWebRequest $request)
  {
		$payment = new Payment();
		$payment->setperson_id($request->getParameter('px_id'));
		$this->px_id = ($request->getParameter('px_id'));
    $this->form = new PaymentPXForm($payment);
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));
		$payment = new Payment();
		$payment->setperson_id($request->getParameter('px_id'));
		$this->px_id = $request->getParameter('px_id');
    $this->form = new PaymentPXForm($payment);

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($payment = Doctrine::getTable('Payment')->find(array($request->getParameter('id'))), sprintf('Object payment does not exist (%s).', array($request->getParameter('id'))));
		$this->px_id = $payment->getperson_id();
    $this->form = new PaymentPXForm($payment);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($payment = Doctrine::getTable('Payment')->find(array($request->getParameter('id'))), sprintf('Object payment does not exist (%s).', array($request->getParameter('id'))));
    $this->form = new PaymentPXForm($payment);

    $this->processForm($request, $this->form);
		$this->px_id = $payment->getperson_id();
    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($payment = Doctrine::getTable('Payment')->find(array($request->getParameter('id'))), sprintf('Object payment does not exist (%s).', array($request->getParameter('id'))));
	  $this->px_id = $payment->getperson_id();
    $payment->delete();

    $this->redirect('px_payment/index?px_id='.$this->px_id);
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()));
    if ($form->isValid())
    {
      $payment = $form->save();
			$this->px_id = $payment->getperson_id();
      $this->redirect('px_payment/edit?id='.$payment['id']);
    }
  }
}
